<template>
  <div class="div">
    <!-- <el-button type="info" @click="logout">清空按钮</el-button> -->
  <el-container class="home-container">
  <el-header>
    <div class="divOfImg"><img src="../assets/logo.png" alt="图标">
    <span>后台管理系统</span>
    </div>
    <el-button type="info" @click="logout">清空按钮</el-button>
    </el-header>

  <el-container >
    <el-aside :width="value? '64px': '200px'">
      <div class="folder" @click="toggleMenu">||||||</div>
<el-menu class="el-menu"
      background-color="black"
      text-color="white"
      active-text-color="#ffd04b"
      :collapse="value"
      :collapse-transition="value1"
      router
      :default-active="activePath"
      >
      <el-submenu :index="item.id+''" v-for="item in menulist" :key="item.id">
        <template slot="title">
          <em class="el-icon-location"></em>
          <span>{{item.authName}}</span>
        </template>
        <!-- 二级菜单 -->
          <el-menu-item :index="'/'+subitem.path+''" v-for="subitem in item.children" :key="subitem.id"
          @click="saveNavState('/'+subitem.path)"
          ><em class="el-icon-menu"></em>
        <span slot="title">{{subitem.authName}}</span></el-menu-item>
      </el-submenu>

      </el-menu-item>
    </el-menu>



    </el-aside>
    <el-container>
      <el-main>
        <router-view></router-view>
      </el-main>

    </el-container>
  </el-container>
</el-container>
  </div>
</template>

<script>
export default {
  data(){
    return {
      menulist :[],
      value:false,
      value1:false,
      activePath:''

    }
  },
  created(){
    this.getMenuList();
    this.activePath = window.sessionStorage.getItem('activePath')

  },

  methods:{
    logout(){
      window.sessionStorage.clear();
      this.$router.push('./login');
    },
    // 获取所有的菜单
   async getMenuList(){
     const {data:res} = await this.$http.get('menus');
    if(res.meta.status != 200) return this.$message.error(res.meta.msg);
    this.menulist = res.data;
    },
    toggleMenu(){
      this.value = !this.value;
    },
    saveNavState(activePath){
      window.sessionStorage.setItem('activePath',activePath)
    }
  }

}
</script>

<style scoped>
.el-header{
  background-color: blanchedalmond;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.el-aside{
  background-color: aquamarine;
}

.el-main{
  background-color: brown;
}


.home-container{
  height:100%;
}

.div{
  height:100%
}
img{
  height:50px
}
.el-menu{
  border-right:none;
}

.folder{
  text-align: center;
  margin: 5px 0;

}
</style>
